<template>
	<view class="container">
		<view class="phone" style="margin-top: 50%;">
			废物宝
		</view>
		<!-- <block v-if="!isAgree">
			<tn-button shape="round" backgroundColor="#1DC069" margin="0rpx 5%" width="90%" height="72rpx"
				fontColor="tn-color-white" openType="getPhoneNumber" @getphonenumber="getPhoneNumber" :blockRepeatClick="true">2微信授权登录</tn-button>
		</block> -->
		<view style="margin-top: 60%;">
			<block>
				<tn-button  shape="round" backgroundColor="#1DC069" margin="0rpx 5%" width="90%" height="72rpx"
					fontColor="tn-color-white" @click="checkIsAgree" :blockRepeatClick="true">1微信授权登录</tn-button>
			</block>
		</view>
		<block v-if="false">
			<view class="wxTip">
				微信一键登录
			</view>
			<view class="wcLogo" @click="wcLogin">
				<!-- <image src="@/pagesMine/static/wechat.png" class="wcLogo" mode=""></image> -->
			</view>
		</block>
		<!-- <view class="agreement">
			<tn-checkbox size="34" labelSize="24" shape="circle" activeColor="#1DC069" v-model="isAgree">登录即代表同意</tn-checkbox><text class="article"  @click="goUser">用户协议</text>和<text class="article" @click="goPrivate">隐私协议</text>
		</view> -->
		 <!-- <OpendateWindow v-model="showAuth" @send="getSonValue"></OpendateWindow> -->
	</view>
</template>
<script>
	import {authLogin} from '@/apis/login.js'
	import {getToken,setToken} from '@/utils/auth';
	import OpendateWindow from '../../components/opendate-Window/opendate-Window.vue';
	export default {
		data() {
			return {
				isAgree:true,
				sessionkey:'',
				openid:'',
				showAuth:true, 
			}
		},
		components:{
			OpendateWindow
		},
		onLoad(options) {
			
		},
		methods: {
			wcLogin(){
				this.tool.toastTip('很抱歉,暂时未开通一键登录!','none',1200);
			},
			checkIsAgree(){
				// if(!this.isAgree){
				// 	this.tool.toastTip('请勾选协议!','none',1500)
				// }else{
				// 	setTimeout(function() {
				// 		uni.navigateBack({
				// 			delta:1
				// 		})
				// 	}, 1200);
				// }
				let that=this;
				uni.login({
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: function(event){
						const {code} = event
						//客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。
						console.log(event)
						uni.getUserInfo({
							provider: 'weixin',
							success: function (infoRes) {
								console.log(infoRes.userInfo); // 打印用户信息
								console.log('用户昵称为: ' + infoRes.userInfo.nickName); // 打印用户昵称
								// 在这里，你可以将用户的头像和昵称保存到本地或者发送到后端进行处理
								// infoRes.userInfo.avatarUrl是用户的头像链接
								// infoRes.userInfo.nickName是用户的昵称
								authLogin({code:code,avatarUrl:infoRes.userInfo.avatarUrl,nickName:infoRes.userInfo.nickName}).then(res => {
									console.log(res)
									if(res.code==200){
										setToken(res.data.id)
										uni.setStorageSync('uid', res.data.id);
										uni.setStorageSync('uinfo', res.data);
										that.tool.toastTip('授权成功!', 'none', 1000)
										setTimeout(() => {
										      uni.navigateTo({
										      	url: '/pages/index/index'
										      })
										}, 2000); // 2000毫秒后执行更新
									}else{
										that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
									}
								}).catch(error => {
									that.tool.toastTip('登录出错,请稍后重试!', 'none', 1000)
								})
							}
						});
						
						
					},
					fail: function (err) {
				        // 登录授权失败
				        // err.code是错误码
				    }
				})

			}
		}
	}
</script>
<style>
	page {
		margin: 0;
		padding: 0;
		height: 100%;
		width: 100%;
	}
	::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
</style>
<style lang="less" scoped>
	.dflex() {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.dflexsb() {
		.dflex();
		justify-content: space-between;
	}
	.dflexsa() {
		.dflex();
		justify-content: space-around;
	}
	.container {
		width: 100%;
		background: #fff;
		font-family: PingFangSC-Semibold, PingFang SC;
		color: #333;
		padding: 30rpx;
		box-sizing: border-box;
		.tipTitle {
			margin-top: 50rpx;
			font-size: 40rpx;
			font-weight: bolder;
			color: #3D3D3D;
		}
		.logo {
			width: 190rpx;
			height: 190rpx;
			.dflex();
			margin: 40rpx auto;
			box-sizing: border-box;
		}
		.phone {
			margin: 30rpx auto;
			font-size: 38rpx;
			font-weight: bolder;
			.dflex();
			color: #3D3D3D;
		}
		.phone:nth-child(1){
			margin-top: 60rpx;
		}
		.wxTip {
			font-size: 24rpx;
			color: #808080;
			margin: 280rpx 0rpx 30rpx 0rpx;
			text-align: center;
		}
		.wcLogo {
			width: 80rpx;
			height: 80rpx;
			.dflex();
			margin: 20rpx auto;
		}
		.agreement{
			.dflex();
			position: fixed;
			bottom: 140rpx;
			left: 0rpx;
			right: 0rpx;
			/deep/.tn-checkbox__label{
				color: #808080;
				font-size: 24rpx;
				margin-right: 0rpx !important;
			}
			.article{
				color: #1DC069;
				margin: 0rpx 4rpx;
				font-weight: bolder;
				font-size: 24rpx;
			}
		}
	}
</style>
